


export class DateUtils {
    /** 
     * 格式化日期
     */
    public static dateFormat = (timestamp: number | Date | string, strFormat = "YYYY-MM-DD"): string => {
        let result = '';
        if (typeof timestamp === 'string') {
            timestamp = +new Date(timestamp);
        }
        const myDate: Date = new Date(+timestamp);
        const YYYY: string = myDate.getFullYear() + "";
        const MM: string = ("00" + (myDate.getMonth() + 1)).slice(-2);
        const DD: string = ("00" + myDate.getDate()).slice(-2);
        const HH: string = ("00" + myDate.getHours()).slice(-2);
        const mm: string = ("00" + myDate.getMinutes()).slice(-2);
        const ss: string = ("00" + myDate.getSeconds()).slice(-2);
        const sss: string = ("" + myDate.getMilliseconds());
        // 星期
        const days = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
        const day: string = days[myDate.getDay()];
        result = strFormat
            .replace(/YYYY/, YYYY)
            .replace(/MM/, MM)
            .replace(/DD/, DD)
            .replace(/HH/, HH)
            .replace(/mm/, mm)
            .replace(/ss/, ss)
            .replace(/sss/, sss)
            .replace(/day/, day);
        return result;
    }

    /** 是否是同一天 */
    public static isSameDay(dateValue1: any, dateValue2: any): boolean {
        const date1 = new Date(dateValue1);
        const date2 = new Date(dateValue2);
        return date1.getFullYear() === date2.getFullYear() &&
            date1.getMonth() === date2.getMonth() &&
            date1.getDate() === date2.getDate();
    }

}